//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.restaurant.application.indexes.exchangegoodslist;

import com.nebutown.base.ViewSpec;
import com.nebutown.base.data.View;
import com.nebutown.base.data.ViewUpdate;
import com.nebutown.commonunits.dataface.DataModes;
import com.nebutown.commonunits.dataface.DateTypes;
import com.nebutown.commonunits.dataface.FormShell;
import com.nebutown.commonunits.dataface.TableShell;
import com.nebutown.commonunits.dataface.definitions.FieldValue;
import com.nebutown.commonunits.dataface.definitions.PageForm;
import com.nebutown.commonunits.dataface.definitions.PageInfo;
import com.nebutown.commonunits.dataface.definitions.TimeInterval;
import com.nebutown.commonunits.uidataface.UIDataFace;
import com.nebutown.commonunits.utils.DateTimeUtils;
import com.nebutown.description.data.SortSpec;
import com.nebutown.generation.basictype.UID;
import com.restaurant.application.goodscoupon.support.GoodsCouponDetail;
import com.restaurant.application.indexes.accumulategoodslist.mysql.AccumulateGoodsListBean;
import com.restaurant.application.indexes.exchangegoodslist.mysql.ExchangeGoodsListBean;
import com.restaurant.application.indexes.exchangegoodslist.mysql.ExchangeGoodsListCriteria;
import com.restaurant.application.indexes.exchangegoodslist.mysql.ExchangeGoodsListImpl;
import com.restaurant.application.indexes.exchangegoodslist.support.AbstractAssistExchangeList;
import com.restaurant.application.indexes.exchangegoodslist.support.ExchangeSearch;
import com.restaurant.application.indexes.goodscouponlist.mysql.GoodsCouponListBean;
import com.restaurant.application.indexes.goodscouponlist.mysql.GoodsCouponListCriteria;
import com.restaurant.application.indexes.goodscouponlist.mysql.GoodsCouponListImpl;
import com.restaurant.application.minifacade.data.CardBO;
import com.restaurant.application.minifacade.data.IdBO;
import com.restaurant.application.util.CommonUtils;
import java.util.List;
import java.util.Objects;

public class AssistExchangeListImpl extends AbstractAssistExchangeList {
    public AssistExchangeListImpl() {
    }

    public View getFullView() {
        return this.newCommonTable(new ExchangeSearch());
    }

    public View getViewLead(ViewSpec spec) {
        return null;
    }

    private View newCommonTable(ExchangeSearch criteria) {
        int pageNum = Objects.nonNull(criteria.getPage()) ? criteria.getPage().intValue() : 1;
        int pageSize = 10;
        int start = (pageNum - 1) * pageSize;
        int stop = pageNum * pageSize;
        int totalRecord = ((ExchangeGoodsListImpl)this.getIndex(ExchangeGoodsListImpl.class)).count(this.getSearchBean(criteria));
        int totalPage = (totalRecord + pageSize - 1) / pageSize;
        List<ExchangeGoodsListBean> search = ((ExchangeGoodsListImpl)this.getIndex(ExchangeGoodsListImpl.class)).search(this.getSearchBean(criteria), CommonUtils.getSort("CREATETIME"), start, stop);
        PageInfo pageInfo = new PageInfo(Integer.valueOf(pageSize), pageNum, totalPage, totalRecord, this.getPath(CMD_DOSEARCH, new int[0]), "page");
        PageForm pageForm = this.newFormShell(criteria, search, pageInfo).getForm();
        return ((UIDataFace)this.getSingleton(UIDataFace.class)).newUniForm(this.unitPosition(), pageForm);
    }

    private FormShell newFormShell(ExchangeSearch criteria, List<ExchangeGoodsListBean> goodsList, PageInfo pageInfo) {
        FormShell formShell = new FormShell("积分商城/兑换记录", 3, 4);
        formShell.source(criteria, DataModes.EDIT);
        formShell.at(0, 0, "手机号").stringField("phone", criteria.getPhone()).placeHolder("手机号").setEditable(true);
        formShell.at(0, 1, "会员名字").stringField("nickName", criteria.getNickName()).placeHolder("名字").setEditable(true);
        formShell.at(0, 2, "会员编号").stringField("customerId", criteria.getCustomerId()).placeHolder("会员编号").setEditable(true);
        formShell.at(1, 0, "兑换时间").intervalField("time", criteria.getTime(), DateTypes.DATETIME).placeHolder("兑换时间").setEditable(true);
        formShell.at(1, 1, "商品Id").stringField("goodsId", criteria.getGoodsId()).placeHolder("商品Id").setEditable(true);
        formShell.at(1, 2, "").buttonField(this.getPath(CMD_DOSEARCH, new int[0]), "搜索", "", true);
        TableShell<AccumulateGoodsListBean> tableShell = (new TableShell(AccumulateGoodsListBean.class, goodsList)).withPageInfo(pageInfo);
        tableShell.createColumn("createTime").withName("时间").cellCalculator((b) -> {
            ExchangeGoodsListBean bean = (ExchangeGoodsListBean)b;
            return (new FieldValue()).withValue(DateTimeUtils.toTime(bean.getCreateTime()));
        });
        tableShell.createColumn("accumulate").withName("积分").cellCalculator((b) -> {
            ExchangeGoodsListBean bean = (ExchangeGoodsListBean)b;
            return (new FieldValue()).withValue(bean.getAccumulate().toString());
        });
        tableShell.createColumn("goodsId").withName("商品Id").cellCalculator((b) -> {
            ExchangeGoodsListBean bean = (ExchangeGoodsListBean)b;
            return (new FieldValue()).withValue(bean.getGoodsId());
        });
        tableShell.createColumn("goodsName").withName("兑换商品").cellCalculator((b) -> {
            ExchangeGoodsListBean bean = (ExchangeGoodsListBean)b;
            return (new FieldValue()).withValue(bean.getGoodsName());
        });
        tableShell.createColumn("customerId").withName("会员编号").cellCalculator((b) -> {
            ExchangeGoodsListBean bean = (ExchangeGoodsListBean)b;
            return (new FieldValue()).withValue(bean.getCustomerId());
        });
        tableShell.createColumn("nickName").withName("会员名字").cellCalculator((b) -> {
            ExchangeGoodsListBean bean = (ExchangeGoodsListBean)b;
            return (new FieldValue()).withValue(bean.getNickName());
        });
        tableShell.createColumn("phone").withName("手机号").cellCalculator((b) -> {
            ExchangeGoodsListBean bean = (ExchangeGoodsListBean)b;
            return (new FieldValue()).withValue(bean.getPhone());
        });
        formShell.at(4, 0, "商品兑换表").large(3, 1).tableField(tableShell);
        return formShell;
    }

    public ViewUpdate doSearch(ExchangeSearch doSearch, int[] seq) {
        return this.returnView(new View[]{this.newCommonTable(doSearch)});
    }

    private ExchangeGoodsListCriteria getSearchBean(ExchangeSearch search) {
        if (Objects.isNull(search.getTime())) {
            search.withTime(new TimeInterval());
        }

        return (new ExchangeGoodsListCriteria()).withPhoneLike(CommonUtils.getNullStr(search.getPhone())).withNickNameLike(CommonUtils.getNullStr(search.getNickName())).withCustomerIdLike(CommonUtils.getNullStr(search.getCustomerId())).withCreateTimeLower(search.getTime().getFrom()).withCreateTimeUpper(search.getTime().getTo()).withGoodsIdLike(search.getGoodsId());
    }

    public List<CardBO> getMyExchangeGoodsList(String status) {
        UID gate = this.getGate();
        List<GoodsCouponListBean> search = ((GoodsCouponListImpl)this.getIndex(GoodsCouponListImpl.class)).search((new GoodsCouponListCriteria()).withCurrentCustomerUidEquals(gate.value()), (SortSpec)null, 1000);
        return null;
    }

    public GoodsCouponDetail getGoodsDetail(IdBO idBO) {
        return null;
    }
}
